feat(config): add config unset to reset a setting to its default#301
Merged
Conversation
dispatch config could list, get, set, edit, and print the path, but the only way to clear one setting back to its default was to edit the file by hand or reset the whole config. Add config unset <key>, which applies the value that key has in a freshly built default config and saves through the normal path, so validation and migrations still run. unset reuses each field's validated setter, so it works uniformly across scalar, enum, duration, and the pointer-backed auto_refresh_seconds field. Unknown keys and bad argument counts return the same style of error as get and set. Shell completion lists unset and the README documents it. While adding the usage line for unset, the printUsage text crossed the Windows os.Pipe buffer size, which made TestPrintUsage_Output deadlock because it drained the pipe only after printUsage returned. The test now drains the pipe from a goroutine so the write cannot block. Closes #296 Co-authored-by: Copilot App <[email protected]>
# Conflicts: # cmd/dispatch/main_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #296
Summary
Adds
dispatch config unset <key>to reset a single setting to its default. Until now the only way to clear one key was to hand-edit the file or reset the whole config.unsetapplies the value the key has in a freshly built default config and saves through the same pathsetuses, so validation and migrations still run. It reuses each field's validated setter, so it works the same for scalar, enum, duration, and the pointer-backedauto_refresh_secondsfield (which resets to unset).getandset.unset, and the README documents it.Note on the test change
Adding the
config unsetline to the help text pushedprintUsageoutput past the Windowsos.Pipebuffer, which madeTestPrintUsage_Outputdeadlock: it drained the pipe only afterprintUsagereturned, so the write blocked once the buffer filled. The test now drains the pipe from a goroutine, which is the portable fix and matches how the same capture pattern should work on any platform.Verification
go build ./...go test ./...(added tests for scalar reset, pointer-field reset, unknown key, both argument-count errors, and a save-error path)go vet ./...golangci-lint run --timeout 10m(0 issues)mage deadcode(OK)